import datetime
import requests
import json

def timeFmt(timeFrom: str,dayNum: int = 0,):
    """计算机时区 +8 time zone 时间格式化 dayNum = 0 今天 -1 昨天 timeFrom eg: %Y-%m-%d %Y%m%d%H%M%S"""
    return (datetime.datetime.now() + datetime.timedelta(days=dayNum, hours=+8)).strftime(timeFrom)

def FileSave(filename,content:str):
    file =  open(filename,"w+",encoding="utf-8")
    file.write(content)
    file.close()

url = 'http://127.0.0.1:8080/api/v1/accounts/01CZ5J6DTPXEAHWZYZG73TPNH9/statuses?limit=999&exclude_replies=true'
# url = 'https://gotosocial-kkbt-tools-xkzlczgovq.cn-hangzhou.fcapp.run/api/v1/accounts/01CZ5J6DTPXEAHWZYZG73TPNH9/statuses?limit=999&exclude_replies=true'
response = requests.get(url)
public_toots = response.json()
print(timeFmt("%Y%m"),"共计",len(public_toots))

backup_str = json.dumps(public_toots,ensure_ascii=False)
if backup_str.endswith("\"回眸一笑百媚生\"}]"):
    print("结尾正确")

FileSave("whispers.tem.json",backup_str)

###### MIN ######
min_public_toots = []

for item in public_toots:
    min_public_toots.append({
        # "id":item['id'],
        "content":item['content'],
        "created_at":item['created_at']
    })

min_public_toots.reverse()

FileSave("whispers.min.json",json.dumps(min_public_toots,ensure_ascii=False))